package org.uim.cricket.entities.bowling;

import java.util.*;

import org.uim.cricket.entities.Player;
import org.uim.cricket.entities.batting.BattingInning;

public class BowlingInning {

	private Player bowler = null;
	private BowlerStatistics statistics = null;
	private List<BattingInning> outBatsmen = null;
	private int bowlingPosition = -1;
	private int bowlingInning = -1;
	
	public void setOutBatsmen(List<BattingInning> outBatsmen) {
		this.outBatsmen = outBatsmen;
	}
	
	public List<BattingInning> getOutBatsmen() {
		return outBatsmen;
	}
	
	public void setStatistics(BowlerStatistics statistics) {
		this.statistics = statistics;
	}

	public void setBowler(Player bowler) {
		this.bowler = bowler;
	}

	public BowlerStatistics getStatistics() {
		return statistics;
	}

	public Player getBowler() {
		return bowler;
	}

	public void sortWickets() {
		if (outBatsmen == null) return;
		Comparator<BattingInning> comp = new Comparator<BattingInning>() {

			@Override
			public int compare(BattingInning b1, BattingInning b2) {
				if (b1==null) return 1;
				if (b2==null) return -1;
				if (b1.getOutDetails() != null && b2.getOutDetails() != null) {
					if (b1.getOutDetails().getOutAsWicket() > b2.getOutDetails().getOutAsWicket()) return 1;
					return -1;
				}
				return 1;
			}
			
		};
		
		Collections.sort(outBatsmen, comp);
	}
	
	public void setBowlingPosition(int bowlingPosition) {
		this.bowlingPosition = bowlingPosition;
	}
	
	public int getBowlingInning() {
		return bowlingInning;
	}
	
	public void setBowlingInning(int bowlingInning) {
		this.bowlingInning = bowlingInning;
	}
	
	public int getBowlingPosition() {
		return bowlingPosition;
	}
}
